<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\Cache;
use think\Db;

/**
 * 版本配置
 * Class appversion
 * @package app\admin\controller
 */
class Appversion extends AdminBase
{
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 版本配置
     */
    public function siteVersion()
    {
        $site_version = Db::name('appversion')->field('value')->where('name', 'site_version')->find();
        $site_version = unserialize($site_version['value']);

        return $this->fetch('site_version', ['site_version' => $site_version]);
    }

    /**
     * 更新配置
     */
    public function updateSiteVersion()
    {
        if ($this->request->isPost()) {
            $site_version                = $this->request->post('site_version/a');
            $site_version['apk_url'] = htmlspecialchars_decode($site_version['apk_url']);
            $data['value']              = serialize($site_version);
            if (Db::name('appversion')->where('name', 'site_version')->update($data) !== false) {
                $this->success('提交成功');
            } else {
                $this->error('提交失败');
            }
        }
    }
}